#include "ScubaSoldierBullet.h"
#include "Box.h"
#include "RSManager.h"
#include "Sprite.h"

ScubaSoldierBullet::ScubaSoldierBullet(SPRITE_ID id) : Object(new Box(), ObjBullet)
{
	_explode = RSManager::getInstance()->getSprite(id);
	_bullet = RSManager::getInstance()->getSprite(GRENADE);
	_sprite = _bullet;
	AssignMove(_box);	
	_id = id;
}


ScubaSoldierBullet::~ScubaSoldierBullet(void)
{
}

void ScubaSoldierBullet::process(ObjectType oType, D3DXVECTOR2 pos, float v, float angle)
{
	_sprite = _bullet;
	_angle = angle;
	_isALive = true;	
	_timeExplode = 0;
	_box->_position = pos;	
	_box->_v.x = _box->_v.y = v;	
	_box->_size = _sprite->getRenderSize();	
	delay = 0;
}

void ScubaSoldierBullet::update()
{
	if(_isALive)
	{
		if(!moveDiagonalThrow1(_angle))
		{					
			delay += GAME_TIME;
			_sprite = _explode;
			if(delay >= 150)
			{
				delay = 0;
				_sprite->Next();
				if(_sprite->GetCurrentIndex() == 0)
					_isALive = false;
			}
		}	
	}
}

void ScubaSoldierBullet::update(float heightLevel)
{	
	if(_isALive)
	{
		if(_box->_position.y <= heightLevel)
			_box->_position.y += 5;			
		else
		{
			delay += GAME_TIME;
			_sprite = _explode;
			if(delay >= 150)
			{
				delay = 0;
				_sprite->Next();
				if(_sprite->GetCurrentIndex() == 0)
					_isALive = false;
			}
		}
	}
}

void ScubaSoldierBullet::render()
{
	if(_isALive)
		_sprite->Render(_box->_position);
}

Box* ScubaSoldierBullet::getCollisionBox()
{
	return _box;
}

bool ScubaSoldierBullet::isAlive()
{
	return _isALive;
	/*if (!_isALive)
	{
	if(_timeExplode >= 250)			
	return false;
	_timeExplode += GAME_TIME;
	}
	return true;	*/
}
